package generator.util

import generator.common.{ExcelReader, Generator}
import org.apache.poi.hssf.usermodel.HSSFSheet
import org.apache.poi.xssf.usermodel.XSSFSheet

import java.io.{File, FileInputStream}

class GenerateFromHSSFExcel[T](excelFileName:String,sheetIndex:Int,getDataSource: HSSFSheet=>T) extends Generator[T] with ExcelReader {
  override var dataSource: T = getDataSource(readHSSFSheet(sheetIndex,excelFileName))
  override def generate(op: T => Unit): Unit = op(dataSource)
}

object GenerateFromHSSFExcel {
  def apply[T](excelFileName: String,sheetIndex:Int,op: HSSFSheet=>T): GenerateFromHSSFExcel[T] = {
    new GenerateFromHSSFExcel(excelFileName,sheetIndex,op) {
    }
  }
}
